package com.sgb.packers.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.sgb.net.entity.ListResponse;
import com.sgb.packers.api.PackersNet;
import com.sgb.packers.entity.ProjectEntity;
import com.sgb.packers.entity.WorkTakeEntity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.common.base.BaseViewModel;

import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @author: 王彬臣
 * @date: 2021/11/24
 * @Description:
 */
public class WorkAccountViewModel extends BaseViewModel {


    public WorkAccountViewModel(@NonNull @NotNull Application application) {
        super(application);
    }

    public MutableLiveData<List<ProjectEntity>> mGetProjectLiveData = new MutableLiveData<>();
    public MutableLiveData<ListResponse<List<WorkTakeEntity>>> mTakeWorkAccountLiveData = new MutableLiveData<>();

    public void getWorkRecords(String projectNo, String year, String month) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("type", 1);
        map.put("projectNo", projectNo);
        map.put("year", year);
        map.put("moth", month);
        PackersNet.getInstance().getService().getWorkRecords(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {

            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {

            }
        });
    }

    public void getProject(Map<String, Object> map) {
        mLoading.postValue(SHOW_LODING);
        PackersNet.getInstance().getService().getProject(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<ProjectEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<ProjectEntity>>> data) {
                mGetProjectLiveData.postValue(data.getData().getList());
            }
        });
    }

    public void takeWorkAccount(Map<String, Object> map) {
        mLoading.postValue(SHOW_LODING);
        PackersNet.getInstance().getService().takeWorkAccount(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<WorkTakeEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<WorkTakeEntity>>> data) {
                mTakeWorkAccountLiveData.postValue(data.getData());
            }
        });
    }
}
